<?php
	MYDCONN();

	if (isset($_GET['CH'])) {
	$GLOBALS['MYD']->db_query("UPDATE ccenter_invoices
						SET 
						Description = '{$_POST['Description']}'
						WHERE Ref = {$_POST['RefInvoice']}");
	} elseif (isset($_GET['CL'])) {
	$GLOBALS['MYD']->db_query("UPDATE ccenter_invoices SET Status = 2, Amount = '{$_POST['Amount']}', TimeEnd = '{$_POST['TimeClose']}',
	 TimeClose = '{$_POST['TimeClose']}', TimePay = '{$_POST['TimeClose']}'
	 WHERE Ref = {$_POST['RefInvoice']}");
	 
	$GLOBALS['MYD']->db_query("INSERT INTO ccenter_invoices
	(CODE, RefProvider, Amount, Status, Time, TimeInvoice, TimeClose, Description, RefOffice, 
	RefUser, sys_USER, ProvIReference, 
	Observations, RefCurrency, TimeEnd, RefContract, TYPE, PayData, Ord) 
	VALUES (0,0,'0.00',1,DATE_ADD('{$_POST['TimeClose']}', INTERVAL 1 DAY),DATE_ADD('{$_POST['TimeClose']}', INTERVAL 1 DAY),DATE_ADD('{$_POST['TimeClose']}', INTERVAL 1 DAY),'',0,0,
	{$_SESSION[$SESSID]},'','',1,DATE_ADD('{$_POST['TimeClose']}', INTERVAL 1 DAY),0,{$_POST['Type']},'',0)");
	}
	
	if (isset($_POST['InsertPlaf'])) {
	$Vars = 'Plaf-'.$_POST['InsertPlaf'];
	$GLOBALS['MYD']->db_query("INSERT ccenter_petty (Office, sysTime, Plafond, sysUser) 
			VALUES ({$_POST['InsertPlaf']}, '{$sysTime}', '{$_POST[$Vars]}', {$_SESSION[$SESSID]})");
	}
	
	if (!isset($Action)) {
		$Msg_OPCONFIRM = "Opera��o Executada.";
	} elseif (isset($_POST['AddInvoice']) || isset($_POST['EditInvoice'])) {
		$Msg_ERROR = "Erro, n�o foi poss�vel conclu�r a opera��o.";
	}
	include($GLOBALS['PAD'].'Modules/CentrodeCustos/Lib/mnginvother.php');
?>